package com.gcloud.controller.network.handler.api.securitygroup.standard;

import org.springframework.beans.factory.annotation.Autowired;

import com.gcloud.controller.ResourceIsolationCheck;
import com.gcloud.controller.enums.ResourceIsolationCheckType;
import com.gcloud.controller.network.service.ISecurityGroupService;
import com.gcloud.core.annotations.CustomAnnotations.GcLog;
import com.gcloud.core.cache.container.CacheContainer;
import com.gcloud.core.cache.enums.CacheType;
import com.gcloud.core.exception.GCloudException;
import com.gcloud.core.handle.ApiHandler;
import com.gcloud.core.handle.MessageHandler;
import com.gcloud.header.ApiVersion;
import com.gcloud.header.Module;
import com.gcloud.header.SubModule;
import com.gcloud.header.network.msg.api.standard.StandardApiDeleteSecurityGroupMsg;
import com.gcloud.header.network.msg.api.standard.StandardApiDeleteSecurityGroupReplyMsg;

@GcLog(taskExpect="删除安全组成功")
@ApiHandler(module=Module.ECS,subModule=SubModule.SECURITYGROUP,action="DeleteSecurityGroup", versions = {ApiVersion.Standard})
@ResourceIsolationCheck(resourceIsolationCheckType = ResourceIsolationCheckType.SECURITYGROUP, resourceIdField = "securityGroupId")
public class StandardApiDeleteSecurityGroupHandler extends MessageHandler<StandardApiDeleteSecurityGroupMsg, StandardApiDeleteSecurityGroupReplyMsg>{

	@Autowired
	ISecurityGroupService securityGroupService;
	
	@Override
	public StandardApiDeleteSecurityGroupReplyMsg handle(StandardApiDeleteSecurityGroupMsg msg) throws GCloudException {
		securityGroupService.deleteSecurityGroup(msg.getSecurityGroupId());
		msg.setObjectId(msg.getSecurityGroupId());
		msg.setObjectName(CacheContainer.getInstance().getString(CacheType.SECURITYGROUP_NAME, msg.getSecurityGroupId()));
		return new StandardApiDeleteSecurityGroupReplyMsg();
	}

}
